<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text" v-model="keyword" placeholder="enter the name you search"/>&nbsp;
      <button @click="search">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";

export default {
  name: "Search",
  data() {
    return {
      keyword: "",
    }
  },
  methods: {
    search() {
      let url = "https://api.github.com/search/users?q=" + this.keyword;
      this.$bus.$emit("searchUsers", {isWelcome: false, isLoading: true, errMsg: '', users: []})
      axios.get(url).then(
          response => {
            console.log("get users. ", response.data)
            this.$bus.$emit("searchUsers", {isWelcome: false, isLoading: false, errMsg: '', users: response.data.items})
          }, error => {
            console.log("had error. ", error.message)
            this.$bus.$emit("searchUsers", {isWelcome: false, isLoading: false, errMsg: error.message, users: []})
          }
      )
    }
  },

}
</script>

<style scoped>

</style>